package com.atguigu.distributed.lock.leecode.greedy;

/**
 * 力扣中等122买卖股票的最佳时机
 */
public class MaxProfit {
    public static void main(String[] args) {
        int [] nums = {7,1,5,3,6,4};
        MaxProfit test = new MaxProfit();
        int i = test.maxProfit(nums);
        System.out.println("res==>"+i);

    }
    public int maxProfit(int[] prices){
        int maxProfit = 0;
        for (int i = 1; i < prices.length; i++) {
            maxProfit += Math.max(0,prices[i]-prices[i-1]);
        }
        return maxProfit;
    }

}
